// 检测是否为纯粹的对象
export const isPlainObject = function isPlainObject(obj) {
    let proto, Ctor;
    if (!obj || Object.prototype.toString.call(obj) !== "[object Object]") return false;
    proto = Object.getPrototypeOf(obj);
    if (!proto) return true;
    Ctor = proto.hasOwnProperty('constructor') && proto.constructor;
    return typeof Ctor === "function" && Ctor === Object;
};

// 具备有效期的LocalStorage
export const store = {
    set(key, value) {
        localStorage.setItem(key, JSON.stringify({
            time: +new Date(),
            data: value
        }))
    },
    get(key, diff = 2592000000) {
        let value = localStorage.getItem(key)
        if (!value) return null
        let { time, data } = JSON.parse(value)
        if (+new Date() - time > diff) {
            localStorage.removeItem(key)
            return null
        }
        return data
    },
    remove(key) {
        localStorage.removeItem(key)
    }
}